package n_swing;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.util.ListResourceBundle;
import java.util.Vector;

import javax.swing.CellRendererPane;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;

public class JComboBoxEx extends JFrame {

	private JPanel contentPane;
	private JComboBox comboBox;
	private JComboBox comboBox_1;
	private JComboBox comboBox_2;
	private JLabel lblAdditem;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JComboBox comboBox_3;
	private JLabel lblNewLabel_3;
	private JComboBox comboBox_4;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JComboBoxEx frame = new JComboBoxEx();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public JComboBoxEx() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 482, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getComboBox());
		contentPane.add(getComboBox_1());
		contentPane.add(getComboBox_2());
		contentPane.add(getLblAdditem());
		contentPane.add(getLblNewLabel());
		contentPane.add(getLblNewLabel_1());
		contentPane.add(getComboBox_3());
		contentPane.add(getLblNewLabel_3());
		contentPane.add(getComboBox_4());
	}
	private JComboBox getComboBox() {
		if (comboBox == null) {
			comboBox = new JComboBox();
			comboBox.setBounds(12, 54, 108, 37);
			comboBox.addItem("A");
			comboBox.addItem("B");
			comboBox.addItem("C");
			comboBox.addItem("D");
			comboBox.addItem("E");
		}
		return comboBox;
	}
	private JComboBox getComboBox_1() {
		if (comboBox_1 == null) {
			Vector<String> v =new Vector<>();
			v.add("가");
			v.add("나");
			v.add("다");
			v.add("라");
			v.add("마");
			comboBox_1 = new JComboBox(v);
			comboBox_1.setBounds(12, 145, 108, 37);
		}
		return comboBox_1;
	}
	private JComboBox getComboBox_2() {
		if (comboBox_2 == null) {
			String str[] ={"아","야","어","여","오","요"};
			comboBox_2 = new JComboBox(str);
			comboBox_2.setBounds(174, 54, 108, 37);
		}
		return comboBox_2;
	}
	private JLabel getLblAdditem() {
		if (lblAdditem == null) {
			lblAdditem = new JLabel("addItem으로 넣기");
			lblAdditem.setBounds(12, 26, 132, 15);
		}
		return lblAdditem;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Vector로 넣기");
			lblNewLabel.setBounds(12, 120, 193, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("배열로 넣기");
			lblNewLabel_1.setBounds(174, 29, 108, 15);
		}
		return lblNewLabel_1;
	}
	private JComboBox getComboBox_3() {
		if (comboBox_3 == null) {
			comboBox_3 = new JComboBox();
			comboBox_3.setBounds(174, 145, 107, 37);
			
			
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo1.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo2.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo3.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo4.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo5.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo6.png"));
			comboBox_3.addItem(new ImageIcon("./src/n_swing/imo7.png"));

		}
		return comboBox_3;
	}
	private JLabel getLblNewLabel_3() {
		if (lblNewLabel_3 == null) {
			lblNewLabel_3 = new JLabel("이미지 넣기");
			lblNewLabel_3.setBounds(174, 120, 108, 15);
		}
		return lblNewLabel_3;
	}
	private JComboBox getComboBox_4() {
		if (comboBox_4 == null) {
			
			String[] str = {"a","b","c"};
			String[] icon = {
					"./src/n_swing/imo1.png",
					"./src/n_swing/imo2.png",
					"./src/n_swing/imo3.png",
					
			};
			
			ComboRender p = new ComboRender(icon);
			
			comboBox_4 = new JComboBox(str);
			comboBox_4.setRenderer(p);
			comboBox_4.setBounds(293, 145, 122, 37);
		}
		return comboBox_4;
	}
	
	
	class ComboRender extends DefaultListCellRenderer{
		String[] icon; 
		int i=0;
		public ComboRender(String[] icon){
			this.icon = icon;
		}

		@Override
		public Component getListCellRendererComponent(JList list, Object value,
				int index, boolean isSelected, boolean cellHasFocus) {
			// TODO Auto-generated method stub
			JLabel l = new JLabel((String)value);
			l.setIcon(new ImageIcon(icon[i]));
				//l.setIcon(new ImageIcon(icon[index]));
			return l;
		}
		
	}
}